import random

def read_prizes():
    prizes = {}
    with open('../data/prizes.txt', 'r') as f:
        for line in f:
            prize, image_path, prob = line.strip().split(':')
            prizes[prize] = {
                'image_path': image_path,
                'prob': float(prob)
            }
    return prizes
def smoke_lottery(prizes):
    # 将百分比转换为小数
    prizes_probs = {prize: info['prob'] / 100.0 for prize, info in prizes.items()}

    total_prob = sum(prizes_probs.values())
    normalized_probs = {prize: prob / total_prob for prize, prob in prizes_probs.items()}

    r = random.random()
    cumulative = 0.0
    for prize, prob in normalized_probs.items():
        cumulative += prob
        if r <= cumulative:
            return prizes[prize]
    return None

prizes = read_prizes()